home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- Module name: Miscellaneous
-
- Author: Gareth Williams.
-
- Function: module containing PHIGS functions which work for both DEC PHIGS
- and SunPHIGS. Also functions which use Ppoint datatypes instead of
- Pvec.
-
- Dependencies:
-
- Internal function list:
-
- External function list:
-
- Hashtables used: none.
-
- Modification history: (Version), (Date), (name), (Description).
-
- 1.0, 5th September 1991, G. Williams, First version.
-
- 2.0, June 1992, G. Williams, Converted to ISO PHIGS C.
-
- ----------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <ctype.h>
- #include <math.h>
- #include <phigs.h>
- #include "ptk.h"
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_delstore(C(Pstore) store)
- PreANSI(Pstore store)
- /*
- ** \parambegin
- ** \param{Pstore}{store}{number of point sets}{IN}
- ** \paramend
- ** \blurb{This function calls DELETE STORE for SunPHIGS and does nothing
- ** for HP PHIGS.}
- */
- {
- /* if HP then don't call since it causes a crash */
- #ifndef HP
- /* do for SUN and PEXSI */
- pdel_store(store);
- #endif
- } /* ptk_delstore */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_fillareaset(C(Pint) numsets, C(Ppoint_list *) sets)
- PreANSI(Pint numsets)
- PreANSI(Ppoint_list *sets)
- /*
- ** \parambegin
- ** \param{Pint}{numsets}{number of point sets}{IN}
- ** \param{Ppoint\_list *}{sets}{list of point sets}{IN}
- ** \paramend
- ** \blurb{This function creates a FILL AREA SET output primitive
- ** and works for both SunPHIGS and DEC PHIGS.}
- */
- {
- Ppoint_list_list ptlist;
-
- ptlist.num_point_lists = numsets;
- ptlist.point_lists = sets;
- pfill_area_set(&ptlist);
- } /* ptk_fillareaset */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_fillareaset3(C(Pint) numsets, C(Ppoint_list3 *) sets)
- PreANSI(Pint numsets)
- PreANSI(Ppoint_list3 *sets)
- /*
- ** \parambegin
- ** \param{Pint}{numsets}{number of point sets}{IN}
- ** \param{Ppoint\_list3 *}{sets}{list of point sets}{IN}
- ** \paramend
- ** \blurb{This function creates a FILL AREA SET3 output primitive
- ** and works for both SunPHIGS and DEC PHIGS.}
- */
- {
- Ppoint_list_list3 ptlist;
-
- ptlist.num_point_lists = numsets;
- ptlist.point_lists = sets;
- pfill_area_set3(&ptlist);
- } /* ptk_fillareaset3 */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqtextextent(C(Pint) wstype, C(Pint) font, C(char *) str,
- C(Pint *) err, C(Prect *) rect)
- PreANSI(Pint wstype)
- PreANSI(Pint font)
- PreANSI(char *str)
- PreANSI(Pint *err)
- PreANSI(Prect *rect)
- /*
- ** \parambegin
- ** \param{Pint}{wstype}{workstation type}{IN}
- ** \param{Pint}{font}{text font}{IN}
- ** \param{char *}{str}{character string}{IN}
- ** \param{Pint *}{error}{error indicator}{OUT}
- ** \param{Prect *}{rect}{text rectangle}{OUT}
- ** \paramend
- ** \blurb{This function simulates the INQUIRE TEXT EXTENT
- ** function for HP PHIGS.}
- */
- {
- switch (font)
- {
- case 1:
- rect->p = ptk_point(0.0, 0.0);
- rect->q = ptk_point(0.01 * strlen(str), 0.01);
- break;
- };
- } /* ptk_inqtextextent */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqcurelemtypesizecontent(C(Pstore) store,
- C(Pint *) error, C(ptkselcontent *) elcontent)
- PreANSI(Pstore store)
- PreANSI(Pint *error)
- PreANSI(ptkselcontent *elcontent)
- /*
- ** \parambegin
- ** \param{Pstore}{store}{data buffer}{OUT}
- ** \param{Pint *}{error}{error indicator}{OUT}
- ** \param{ptkselcontent *}{elcontent}{element content data record}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain the type, size and
- ** contents of the current element. The data buffer is used to store
- ** the element contents data and is allocated by the function. The
- ** buffer should be deallocated by the application when the element
- ** data is no longer required. This function works with both SunPHIGS
- ** and DEC PHIGS.}
- */
- {
- size_t size;
- Pint bufsize;
-
- pinq_cur_elem_type_size(error, &elcontent->eltype, &size);
- if ((*error != 0) || (elcontent->eltype == PELEM_NIL))
- return;
- else
- pinq_cur_elem_content(store, error, &elcontent->eldata);
- } /* ptk_inqcurelemtypesizecontent */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqcurelemtype(C(Pint *) error, C(Pelem_type *) eltype)
- PreANSI(Pint *error)
- PreANSI(Pelem_type *eltype)
- /*
- ** \parambegin
- ** \param{Pint *}{error}{error indicator}{OUT}
- ** \param{Pelem\_type *}{eltype}{element type}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain the current element type
- ** and works for both SunPHIGS and DEC PHIGS.}
- */
- {
- size_t size;
-
- pinq_cur_elem_type_size(error, eltype, &size);
- } /* ptk_inqcurelemtype */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqelemtypesizecontent(C(Pint) stid, C(Pint) elemid,
- C(Pstore) store, C(Pint *) error,
- C(ptkselcontent *) elcontent)
- PreANSI(Pint stid)
- PreANSI(Pint elemid)
- PreANSI(Pstore store)
- PreANSI(Pint *error)
- PreANSI(ptkselcontent *elcontent)
- /*
- ** \parambegin
- ** \param{Pint}{stid}{structure identifier}{IN}
- ** \param{Pint}{elemid}{element number}{IN}
- ** \param{Pstore}{store}{data buffer}{OUT}
- ** \param{Pint *}{error}{error indicator}{OUT}
- ** \param{ptkselcontent *}{elcontent}{element content data record}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain the type, size and
- ** contents of element {\tt elemid} in structure {\tt stid}.
- ** The data buffer is used to store
- ** the element contents data and is allocated by the function. The
- ** buffer should be deallocated by the application when the element
- ** data is no longer required. This function works with both SunPHIGS
- ** and DEC PHIGS.}
- */
- {
- size_t size;
- Pint bufsize;
-
- pinq_elem_type_size(stid, elemid, error, &elcontent->eltype, &size);
- if ((*error != 0) || (elcontent->eltype == PELEM_NIL))
- return;
- else
- pinq_elem_content(stid, elemid, store, error, &elcontent->eldata);
- } /* ptk_inqelemtypesizecontent */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqelemtype(C(Pint) stid, C(Pint) elemid, C(Pint *) error,
- C(Pelem_type *) eltype)
- PreANSI(Pint stid)
- PreANSI(Pint elemid)
- PreANSI(Pint *error)
- PreANSI(Pelem_type *eltype)
- /*
- ** \parambegin
- ** \param{Pint}{stid}{structure identifier}{IN}
- ** \param{Pint}{elemid}{element number}{IN}
- ** \param{Pint *}{error}{error indicator}{OUT}
- ** \param{Pelem\_type *}{eltype}{element type}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain the element type of
- ** element {\tt elemid} in structure {\tt stid}
- ** and works for both SunPHIGS and DEC PHIGS.}
- */
- {
- size_t size;
-
- pinq_elem_type_size(stid, elemid, error, eltype, &size);
- } /* ptk_inqelemtype */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_pscale(C(Ppoint *) scalept, C(Pint *) err, C(Pmatrix) mat)
- PreANSI(Ppoint *scalept)
- PreANSI(Pint *err)
- PreANSI(Pmatrix mat)
- /*
- ** \parambegin
- ** \param{Ppoint *}{scalept}{scale vector}{IN}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \param{Pmatrix}{mat}{3x3 matrix}{OUT}
- ** \paramend
- ** \blurb{This function performs the SCALE function using a {\tt Ppoint}
- ** datatype instead of {\tt Pvec}.}
- */
- {
- Pvec vec;
-
- vec = ptk_vector(scalept->x, scalept->y);
- pscale(&vec, err, mat);
- } /* ptk_pscale */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_pscale3(C(Ppoint3 *) scalept, C(Pint *) err, C(Pmatrix3) mat)
- PreANSI(Ppoint3 *scalept)
- PreANSI(Pint *err)
- PreANSI(Pmatrix3 mat)
- /*
- ** \parambegin
- ** \param{Ppoint3 *}{scalept}{scale vector}{IN}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \param{Pmatrix3}{mat}{4x4 matrix}{OUT}
- ** \paramend
- ** \blurb{This function performs the SCALE3 function using a {\tt Ppoint3}
- ** datatype instead of {\tt Pvec3}.}
- */
- {
- Pvec3 vec;
-
- vec = ptk_vector3(scalept->x, scalept->y, scalept->z);
- pscale3(&vec, err, mat);
- } /* ptk_pscale3 */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_psetcharup(C(Ppoint *) pt)
- PreANSI(Ppoint *pt)
- /*
- ** \parambegin
- ** \param{Ppoint *}{pt}{character up vector}{IN}
- ** \paramend
- ** \blurb{This function performs the SET CHARACTER UP VECTOR function
- ** using a {\tt Ppoint} datatype instead of {\tt Pvec}.}
- */
- {
- Pvec vec;
-
- vec = ptk_vector(pt->x, pt->y);
- pset_char_up_vec(&vec);
- } /* ptk_psetcharup */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_psetannotationcharup(C(Ppoint *) pt)
- PreANSI(Ppoint *pt)
- /*
- ** \parambegin
- ** \param{Ppoint *}{pt}{annotation character up vector}{IN}
- ** \paramend
- ** \blurb{This function performs the SET ANNOTATION CHARACTER UP VECTOR
- ** function using a {\tt Ppoint} datatype instead of {\tt Pvec}.}
- */
- {
- Pvec vec;
-
- vec = ptk_vector(pt->x, pt->y);
- pset_anno_char_up_vec(&vec);
- } /* ptk_psetannotationcharup */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_ptranslate(C(Ppoint *) tranpt, C(Pint *) err, C(Pmatrix) mat)
- PreANSI(Ppoint *tranpt)
- PreANSI(Pint *err)
- PreANSI(Pmatrix mat)
- /*
- ** \parambegin
- ** \param{Ppoint *}{tranpt}{translation vector}{IN}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \param{Pmatrix}{mat}{3x3 matrix}{OUT}
- ** \paramend
- ** \blurb{This function performs the TRANSLATE function using a {\tt Ppoint}
- ** datatype instead of {\tt Pvec}.}
- */
- {
- Pvec vec;
-
- vec = ptk_vector(tranpt->x, tranpt->y);
- ptranslate(&vec, err, mat);
- } /* ptk_ptranslate */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_ptranslate3(C(Ppoint3 *) tranpt, C(Pint *) err,
- C(Pmatrix3) mat)
- PreANSI(Ppoint3 *tranpt)
- PreANSI(Pint *err)
- PreANSI(Pmatrix3 mat)
- /*
- ** \parambegin
- ** \param{Ppoint3 *}{tranpt}{translation vector}{IN}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \param{Pmatrix3}{mat}{4x4 matrix}{OUT}
- ** \paramend
- ** \blurb{This function performs the TRANSLATE3 function using a {\tt Ppoint3}
- ** datatype instead of {\tt Pvec3}.}
- */
- {
- Pvec3 vec;
-
- vec = ptk_vector3(tranpt->x, tranpt->y, tranpt->z);
- ptranslate3(&vec, err, mat);
- } /* ptk_ptranslate3 */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_pbuildtran(C(Ppoint *) pt, C(Ppoint *) shift,
- C(Pfloat) angle, C(Ppoint *) scale,
- C(Pint *) err, C(Pmatrix) mat)
- PreANSI(Ppoint *pt)
- PreANSI(Ppoint *shift)
- PreANSI(Pfloat angle)
- PreANSI(Ppoint *scale)
- PreANSI(Pint *err)
- PreANSI(Pmatrix mat)
- /*
- ** \parambegin
- ** \param{Ppoint *}{pt}{fixed point}{IN}
- ** \param{Ppoint *}{shift}{shift vector}{IN}
- ** \param{Pfloat}{angle}{rotation angle}{IN}
- ** \param{Ppoint *}{scale}{scale vector}{IN}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \param{Pmatrix}{mat}{3x3 matrix}{OUT}
- ** \paramend
- ** \blurb{This function performs the BUILD TRANSFORMATION MATRIX
- ** function using the {\tt Ppoint} datatype instead of {\tt Pvec}.}
- */
- {
- Pvec vec1, vec2;
-
- vec1 = ptk_vector(shift->x, shift->y);
- vec2 = ptk_vector(scale->x, scale->y);
- pbuild_tran_matrix(pt, &vec1, angle, &vec2, err, mat);
- } /* ptk_pbuildtran */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_pbuildtran3(C(Ppoint3 *) pt, C(Ppoint3 *) shift,
- C(Pfloat) xangle, C(Pfloat) yangle, C(Pfloat) zangle,
- C(Ppoint3 *) scale, C(Pint *) err, C(Pmatrix3) mat)
- PreANSI(Ppoint3 *pt)
- PreANSI(Ppoint3 *shift)
- PreANSI(Pfloat xangle)
- PreANSI(Pfloat yangle)
- PreANSI(Pfloat zangle)
- PreANSI(Ppoint3 *scale)
- PreANSI(Pint *err)
- PreANSI(Pmatrix3 mat)
- /*
- ** \parambegin
- ** \param{Ppoint3 *}{pt}{fixed point}{IN}
- ** \param{Ppoint3 *}{shift}{shift vector}{IN}
- ** \param{Pfloat}{xangle}{x rotation angle}{IN}
- ** \param{Pfloat}{yangle}{y rotation angle}{IN}
- ** \param{Pfloat}{zangle}{z rotation angle}{IN}
- ** \param{Ppoint3 *}{scale}{scale vector}{IN}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \param{Pmatrix3}{mat}{4x4 matrix}{OUT}
- ** \paramend
- ** \blurb{This function performs the BUILD TRANSFORMATION MATRIX3
- ** function using the {\tt Ppoint3} datatype instead of {\tt Pvec3}.}
- */
- {
- Pvec3 vec1, vec2;
-
- vec1 = ptk_vector3(shift->x, shift->y, shift->z);
- vec2 = ptk_vector3(scale->x, scale->y, scale->z);
- pbuild_tran_matrix(pt, &vec1, xangle, yangle, zangle, &vec2, err, mat);
- } /* ptk_pbuildtran3 */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_pcomposetran(C(Pmatrix) mat, C(Ppoint *) pt,
- C(Ppoint *) shift, C(Pfloat) angle, C(Ppoint *) scale,
- C(Pint *) err, C(Pmatrix) result)
- PreANSI(Pmatrix mat)
- PreANSI(Ppoint *pt)
- PreANSI(Ppoint *shift)
- PreANSI(Pfloat angle)
- PreANSI(Ppoint *scale)
- PreANSI(Pint *err)
- PreANSI(Pmatrix result)
- /*
- ** \parambegin
- ** \param{Pmatrix}{mat}{3x3 matrix}{IN}
- ** \param{Ppoint *}{pt}{fixed point}{IN}
- ** \param{Ppoint *}{shift}{shift vector}{IN}
- ** \param{Pfloat}{angle}{rotation angle}{IN}
- ** \param{Ppoint *}{scale}{scale vector}{IN}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \param{Pmatrix}{result}{3x3 matrix}{OUT}
- ** \paramend
- ** \blurb{This function performs the COMPOSE TRANSFORMATION MATRIX
- ** function using the {\tt Ppoint} datatype instead of {\tt Pvec}.}
- */
- {
- Pvec vec1, vec2;
-
- vec1 = ptk_vector(shift->x, shift->y);
- vec2 = ptk_vector(scale->x, scale->y);
- pbuild_tran_matrix(mat, pt, &vec1, angle, &vec2, err, result);
- } /* ptk_pcomposetran */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_pcomposetran3(C(Pmatrix3) mat, C(Ppoint3 *) pt,
- C(Ppoint3 *) shift, C(Pfloat) xangle, C(Pfloat) yangle,
- C(Pfloat) zangle, C(Ppoint3 *) scale, C(Pint *) err, C(Pmatrix3) result)
- PreANSI(Pmatrix3 mat)
- PreANSI(Ppoint3 *pt)
- PreANSI(Ppoint3 *shift)
- PreANSI(Pfloat xangle)
- PreANSI(Pfloat yangle)
- PreANSI(Pfloat zangle)
- PreANSI(Ppoint3 *scale)
- PreANSI(Pint *err)
- PreANSI(Pmatrix3 result)
- /*
- ** \parambegin
- ** \param{Pmatrix3}{mat}{4x4 matrix}{OUT}
- ** \param{Ppoint3 *}{pt}{fixed point}{IN}
- ** \param{Ppoint3 *}{shift}{shift vector}{IN}
- ** \param{Pfloat}{xangle}{x rotation angle}{IN}
- ** \param{Pfloat}{yangle}{y rotation angle}{IN}
- ** \param{Pfloat}{zangle}{z rotation angle}{IN}
- ** \param{Ppoint3 *}{scale}{scale vector}{IN}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \param{Pmatrix3}{result}{4x4 matrix}{OUT}
- ** \paramend
- ** \blurb{This function performs the COMPOSE TRANSFORMATION MATRIX3
- ** function using the {\tt Ppoint3} datatype instead of {\tt Pvec3}.}
- */
- {
- Pvec3 vec1, vec2;
-
- vec1 = ptk_vector3(shift->x, shift->y, shift->z);
- vec2 = ptk_vector3(scale->x, scale->y, scale->z);
- pbuild_tran_matrix(mat, pt, &vec1, xangle, yangle, zangle, &vec2, err, result);
- } /* ptk_pcomposetran3 */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_pevalvieworientationmatrix(C(Ppoint *) vrp, C(Ppoint *) vup,
- C(Pint *) err, C(Pmatrix) mat)
- PreANSI(Ppoint *vrp)
- PreANSI(Ppoint *vup)
- PreANSI(Pint *err)
- PreANSI(Pmatrix mat)
- /*
- ** \parambegin
- ** \param{Ppoint *}{vrp}{view reference point}{IN}
- ** \param{Ppoint *}{vup}{view up vector}{IN}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \param{Pmatrix}{mat}{3x3 matrix}{OUT}
- ** \paramend
- ** \blurb{This function performs the EVALUATE VIEW ORIENTATION MATRIX
- ** function using the {\tt Ppoint3} datatype instead of {\tt Pvec3}.}
- */
- {
- Pvec vec;
-
- vec = ptk_vector(vup->x, vup->y);
- peval_view_ori_matrix(vrp, &vec, err, mat);
- } /* ptk_pevalvieworientationmatrix */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_pevalvieworientationmatrix3(C(Ppoint3 *) vrp,
- C(Ppoint3 *) vpn, C(Ppoint3 *) vup, C(Pint *) err,
- C(Pmatrix3) mat)
- PreANSI(Ppoint3 *vrp)
- PreANSI(Ppoint3 *vpn)
- PreANSI(Ppoint3 *vup)
- PreANSI(Pint *err)
- PreANSI(Pmatrix3 mat)
- /*
- ** \parambegin
- ** \param{Ppoint3 *}{vrp}{view reference point}{IN}
- ** \param{Ppoint3 *}{vup}{view up vector}{IN}
- ** \param{Ppoint3 *}{vpn}{view plane normal}{IN}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \param{Pmatrix}{mat}{3x3 matrix}{OUT}
- ** \paramend
- ** \blurb{This function performs the EVALUATE VIEW ORIENTATION MATRIX3
- ** function using the {\tt Ppoint3} datatype instead of {\tt Pvec3}.}
- */
- {
- Pvec3 vec1, vec2;
-
- vec1 = ptk_vector3(vpn->x, vpn->y, vpn->z);
- vec2 = ptk_vector3(vup->x, vup->y, vup->z);
- peval_view_ori_matrix3(vrp, &vec1, &vec2, err, mat);
- } /* ptk_pevalvieworientationmatrix3 */
-
- /*--------------------------------------------------------------------------*/
-
- extern ptkboolean pt3inlimit3(C(Ppoint3 *) pt3, C(Plimit3 *) limit3)
- PreANSI(Ppoint3 *pt3)
- PreANSI(Plimit3 *limit3)
- {
- return ((pt3->x >= limit3->x_min) && (pt3->x <= limit3->x_max)
- && (pt3->y >= limit3->y_min) && (pt3->y <= limit3->y_max)
- && (pt3->z >= limit3->z_min) && (pt3->z <= limit3->z_max));
- }
-
- /*--------------------------------------------------------------------------*/
-
- extern ptkboolean ptinlimit3(C(Ppoint *) pt, C(Plimit3 *) limit3)
- PreANSI(Ppoint *pt)
- PreANSI(Plimit3 *limit3)
- {
- return ((pt->x >= limit3->x_min) && (pt->x <= limit3->x_max)
- && (pt->y >= limit3->y_min) && (pt->y <= limit3->y_max)
- && (0.0 >= limit3->z_min) && (0.0 <= limit3->z_max));
- }
-
- /*--------------------------------------------------------------------------*/
-
- extern Pint instrlist(C(char **) strlist, C(Pint) lenlist, C(char *) str)
- PreANSI(char **strlist)
- PreANSI(Pint lenlist)
- PreANSI(char *str)
- /*
- ** description: searches list of strings for given string.
- ** input params: strlist - pointer to string list.
- ** lenlist - length of string list.
- ** str - string to search.
- ** output params: none.
- ** return value: index of found string, -1 if not found.
- ** special notes:
- */
- {
- ptkboolean found;
- Pint i;
-
- found = FALSE;
- i = 0;
- while ((found == FALSE) && (i < lenlist))
- {
- if (strcmp(strlist[i], str) == 0)
- found = TRUE;
- else
- i++;
- }
- if (found == FALSE)
- return -1;
- else
- return i;
- } /* instrlist */
-
- /*--------------------------------------------------------------------------*/
-
- extern Pint inintlst(C(Pint) n, C(Pint_list *) list)
- PreANSI(Pint n)
- PreANSI(Pint_list *list)
- /*
- ** description: search for integer in integer list.
- ** input params: n - integer to search for.
- ** list - list of integers to search in.
- ** output params: none.
- ** return value: TRUE if integer in list, otherwise FALSE.
- */
- {
- Pint i;
- ptkboolean found;
-
- i = 0;
- found = FALSE;
- while (!found && (i < list->num_ints))
- {
- if (list->ints[i] == n)
- found = TRUE;
- else
- i++;
- }
- if (found == FALSE)
- return -1;
- else
- return i;
- } /* inintlst */
-
- /*--------------------------------------------------------------------------*/
-
- extern void addtointlst(C(Pint) addint, C(Pint_list *) list)
- PreANSI(Pint addint)
- PreANSI(Pint_list *list)
- {
- if (inintlst(addint, list) == -1)
- {
- (list->num_ints)++;
- list->ints[list->num_ints - 1] = addint;
- }
- } /* addtointlst */
-
- /*--------------------------------------------------------------------------*/
-
- extern void removefromintlst(C(Pint) remint, C(Pint_list *) list)
- PreANSI(Pint remint)
- PreANSI(Pint_list *list)
- {
- Pint j, ind;
-
- if ((ind = inintlst(remint, list)) != -1)
- {
- for (j = ind; j < list->num_ints - 1; j++)
- list->ints[j] = list->ints[j + 1];
- (list->num_ints)--;
- }
- } /* removefromintlst */
-
- /*--------------------------------------------------------------------------*/
-
- extern void strupper(C(char *) str)
- PreANSI(char *str)
- {
- Pint ind, strlength;
-
- strlength = strlen(str);
- for (ind = 0; ind < strlength; ind++)
- {
- if (islower(str[ind]))
- str[ind] = str[ind] + ('A' - 'a');
- }
- } /* strupper */
-
- /*--------------------------------------------------------------------------*/
-
- extern void strlower(C(char *) str)
- PreANSI(char *str)
- {
- Pint ind, strlength;
-
- strlength = strlen(str);
- for (ind = 0; ind < strlength; ind++)
- {
- if (isupper(str[ind]))
- str[ind] = str[ind] - ('A' - 'a');
- }
- } /* strlower */
-
- /*--------------------------------------------------------------------------*/
-
- extern Pint stringlength(C(char *)str)
- PreANSI(char *str)
- /*
- ** description: returns length of string up to first ' '(space), '\n' or '\0'
- ** character.
- ** input params: str - string to find length of.
- ** return value: length of string.
- ** special notes: The hashstrings algorithm does not permit strings with
- ** spaces, hence the search for the first space character. The C library
- ** routine `strlen' assumes there is a `\0' character terminating the string,
- ** however it is safer to look for a `\n' character aswell.
- */
- {
- ptkboolean charfound;
- Pint ind;
-
- ind = 0;
- charfound = FALSE;
- while (!charfound)
- {
- if (str[ind] == ' ' || str[ind] == '\n' || str[ind] == '\0')
- charfound = TRUE;
- else
- ind++;
- }
- return ind;
- } /* stringlength */
-
- /*--------------------------------------------------------------------------*/
-
- /* end of misc.c */
-